Deep learning enhanced code completion system

ABSTRACT

A code completion tool uses a deep learning model to predict the likelihood of a method completing a method invocation. In one aspect, the deep learning model is a LSTM trained on features that represent the syntactic context of a method invocation derived from an abstract tree representation of the code fragment.

CROSS-REFERENCE TO RELATED APPLICATIONS

The present application claims the benefit of the earlier filedprovisional application having Ser. No. 62/800,460 filed on Feb. 2,2019, which is hereby incorporated by reference.

BACKGROUND

Software development environments are often used to aid softwaredevelopers (i.e., users, programmers, etc.) to develop program code. Thesoftware development environment may include a source code editor andother tools that a developer utilizes to write and test their programs.Some software development environments include a code completion featurethat provides assistance while the developer is editing code byautomatically presenting a list of possible candidates based on one ormore characters (e.g., letters, symbols, etc.) that a developer hastyped into a source code editor. A popup menu may appear with severalsuggested code elements that the developer may utilize. This assistanceis beneficial since it speeds up the development time and reduces commonerrors, such as typos. However, the automatic code completion featuremay be problematic when there is a large list of candidates which maynot be relevant and/or which may be too lengthy for a developer tobrowse through to find the right element.

SUMMARY

This Summary is provided to introduce a selection of concepts in asimplified form that are further described below in the DetailedDescription. This Summary is not intended to identify key features oressential features of the claimed subject matter, nor is it intended tobe used to limit the scope of the claimed subject matter.

A code completion system uses a deep learning model to generatecandidates to automatically complete a method invocation. The deeplearning network model is trained to predict the most likely method tocomplete a method invocation from ordered sequences of tokensrepresenting the syntactic representation of the context of the methodinvocation from historical usage patterns of the method invocation. Inone aspect, the deep learning model is a long short term memory model(LSTM). The LSTM is capable of learning order dependence in sequentialpatterns such as the ordered sequence of tokens obtained from anabstract syntax tree representing a code snippet containing the methodinvocation. The ordered sequence of tokens includes the syntax nodes andtokens from the abstract syntax tree and the runtime datatype of thevariable assigned the result of the method invocation.

These and other features and advantages will be apparent from a readingof the following detailed description and a review of the associateddrawings. It is to be understood that both the foregoing generaldescription and the following detailed description are explanatory onlyand are not restrictive of aspects as claimed.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 illustrates an exemplary code completion system having a trainingphase that generates a deep learning model and an inference phase thatuses the deep learning model to predict one or more candidates tocomplete a method invocation.

FIG. 2 is a schematic diagram illustrating an embodiment of anarchitecture of the deep learning model.

FIG. 3 is a flow diagram illustrating an exemplary method for generatingthe deep learning model.

FIG. 4 is a schematic diagram illustrating the batching of the trainingdataset used to train the deep learning model.

FIG. 5 is a flow diagram illustrating an exemplary method for utilizingthe deep learning model for code completion.

FIG. 6 is a block diagram illustrating an operating environment.

DETAILED DESCRIPTION

Overview

The subject matter disclosed pertains to the generation of candidates toautomatically complete a method invocation using a deep learning networkmodel. The deep learning network model is trained to predict the mostlikely method to complete a method invocation from ordered sequences oftokens corresponding to the syntactic representation of the context of amethod invocation. In one aspect, the deep learning model is a LongShort-Term Memory (LSTM) network. The LSTM is capable of learning orderdependence in sequential patterns such as the ordered sequence of tokensobtained from an abstract syntax tree representing a code snippetcontaining a method invocation. The ordered sequence of tokens includesthe syntactic context and the runtime data type of the variable assignedthe result of the method invocation.

A method invocation is the issuance of a call to a method, field orproperty of a class. The method invocation may be invoked with zero ormore parameters. A method invocation includes member access expressions,module function invocations, and remote method invocations, such asapplication programming interfaces (APIs). A member access expression isan expression that represents access to a field or property of a class.A module function invocation is a call to a method or property of aclass including its parameters and includes remote procedure calls, suchas application programming interface calls.

A class may include a large number of methods and/or properties therebymaking it impractical to list all the methods and properties of a classas candidates. In order to generate the candidates more likely tocomplete a source code statement invoking a method, the context in whichthe method is invoked is used to predict the more likely candidates. Inone aspect, an ordered sequence of tokens based on an abstract syntacticrepresentation of the source code preceding a method invocation and themethod invocation is used as the basis to predict the candidates. Theordered sequence of tokens representing the surrounding source codecontext can be obtained from an abstract syntactic representation of themethod invocation, such as from an abstract syntax tree.

Machine learning uses different types of statistical methods to learnfrom data and to predict future decisions. Traditional machine learningincludes classification models, data mining, Bayesian networks, Markovmodels, clustering, and visual data mapping. Deep learning differs frommachine learning since it uses multiple stages of data processingthrough many hidden layers of a neural network to learn and interpretthe features and the relationships between the features. Deep learningembodies neural networks which differs from the traditional machinelearning techniques that do not use neural networks.

Attention now turns to a further discussion of the system, devices,components, and methods utilized in a code completion system.

Machine Learning Code Completion System

FIG. 1 illustrates a block diagram of an exemplary code completionsystem 100 in which various aspects of the invention may be practiced.As shown in FIG. 1, system 100 includes a training phase 102 whichtrains a deep learning model 122 and an inference phase 104 thatutilizes the deep learning model 122. The training phase 102 may utilizea source code extraction component 108, a compilation component 112, atoken sequence extraction component 116, and a model training component120.

In the training phase 102, the source code extraction component 108extracts source code programs 110 from a source code repository 106 toobtain training and validation datasets. The source code repository 106is a file archive and web hosting facility that stores large amounts ofsource code either privately or publicly. The source code repository canbe structured as a version control system, such as GIT, Mercurial, etc.The source code programs residing in the source code repository 106 varyand may be written in different programming languages. The source codeextraction component 108 obtains source code programs written in thesame programming language that utilizes the same context-free grammarfor the training and validation datasets. A context-free grammar is aset of rules that describe all possible strings in a formal language.The source code programs can come from different domains, such aswithout limitation, scientific computing, web development, dataflowprogramming, machine learning, and the like but are written in the sameprogramming language.

A compilation component 112 transforms each of the selected source codeprograms 110 into an abstract syntax tree 114. In one aspect, thecompilation component 112 may be a front-end compiler, a parser, or alanguage compiler. An abstract syntax tree 114 represents the syntacticstructure of the program in a hierarchical or tree structure. Theabstract syntax tree 114 is an n-ary tree data structure that includesnodes that represent a construct in the grammar of the programminglanguage of a program. The abstract syntax tree 114 includes one rootnode, multiple internal nodes, and multiple leaf nodes. The internalnodes are labeled by operators and the leaf nodes represent the operandsof the operators. A leaf node contains a token representing the operandof an operator and an internal node includes a token representing theoperator. A token is a symbol that represents an operand and anoperator.

The abstract syntax tree 114 for a selected source code program 110 ispassed to the token sequence extraction component 116. The tokensequence extraction component 116 uses a portion of the abstract syntaxtree 114 that represents the context of a method invocation as input fortraining the deep learning model. The abstract syntax tree 114 istraversed in depth-first order to extract a T-ordered sequence of tokensrepresenting the context of the method invocation. The T-orderedsequence of tokens includes the tokens immediately preceding theinitiation of a method invocation. The tokens representing the methodinvocation include the method invocation and the runtime data type ofthe variable assigned the return value of the method invocation. Theruntime data type of the variable assigned the return value of themethod invocation may be inferred using traditional compiler typeinference methods if the data type is not already declared in the sourcecode program. The number of tokens, T, in the ordered sequence ispre-configured and a tunable parameter based on various factors, such asthe model's prediction accuracy.

The feature vectors or T-ordered sequences of tokens are then mappedinto numeric vectors and then into a word embedding. A word embedding isa learned representation for the text-based tokens where words that havea common meaning have a common representation. Various natural languageprocessing techniques may be used to generate the word embeddings. Inone aspect, Word2vec, is used to produce the word embeddings. Word2vecis a two-layer neural network trained to produce a vector space from alarge dataset of text, such as the vocabulary of the tokens associatedwith the ordered sequences.

The word embeddings 118 are input to the model training component 120.The model training component 120 uses the word embeddings 118 togenerate a deep learning model 122 capable of producing potentialcandidates likely to complete a method invocation given a particularcode snippet. The deep learning model 122 predicts the method bestsuited to complete a method invocation, given code snippet C, vocabularyV, and the set of all possible methods M in V, by finding the methodm*=argmax (P(m|C)), for all mϵM. In one aspect, the model trainingcomponent 120 trains a LSTM. The LSTM is trained offline with the wordembeddings 118 and tuned to achieve a desired performance.

The deep learning model 122 is used in the inference phase 104 of thecode completion system. In one or more aspects, the inference phase 104may be embodied as a function or feature integrated into a source codeeditor, integrated development environment (IDE), and/or stand-aloneapplication. Code completion may be embodied as a tool or feature thatcan be an add-on, plug-in, extension and/or component of a source codeeditor and/or IDE. In one aspect, the inference phase 104 includes asource code editor 130 having a user interface 132 and a parser 134 anda code completion component 142. The code completion component 142includes a token sequence extraction component 116 that generates wordembeddings from the abstract syntax tree 140 and passes the wordembeddings to the deep learning model 122.

In one aspect, a source code editor 130 may include a user interface 132and a parser 134. The user interface 132 includes a set of features orfunctions for developing (e.g., writing, editing, testing) a source codeprogram. The user interface 132 may utilize a pop-up window to present alist of possible candidates for completion thereby allowing a developerto browse through the candidates and to select one from the list. Theparser 134 reads the source code in the source code editor 130 andgenerates a corresponding abstract syntax tree 140. The parser 134 alsoupdates the abstract syntax tree 140 as the developer creates and editsthe source code in the source code editor 130.

At certain points in the editing process, the user interface 132 willdetect that the user has entered a particular character which willinitiate code completion. This character is referred to as a markercharacter. In one aspect, the marker character may be a period, “.”,placed after a class name. The user interface 132 will then sendrequests 138 for candidates from the code completion component 142 topresent to the developer.

The code completion component 142 receives the requests 138 forcandidates to complete a method invocation. The token sequenceextraction component 116 extracts the T-ordered sequence of tokens fromthe abstract syntax tree 140 representing the source code context of theinitiation of a method invocation in the source code editor. TheT-ordered sequence of tokens in this case include the marker characterand the tokens preceding the marker character.

The T-ordered sequence of tokens is transformed into word embeddings144, as noted above, and then input into the deep learning model 122which generates probabilities for a number of candidates. The candidatesare ranked according to their respective probability with the candidateshaving the highest probability at the top. A select number of candidates136 is then returned to the source code editor 130 and displayed in theuser interface 132.

It should be noted that FIG. 1 shows components of the system in oneaspect of an environment in which various aspects of the invention maybe practiced. However, the exact configuration of the components shownin FIG. 1 may not be required to practice the various aspects andvariations in the configuration shown in FIG. 1 and the type ofcomponents may be made without departing from the spirit or scope of theinvention. For example, the training phase 102 may be executed in onecomputing environment and the inference phase 104 may be executed in thesame computing environment or in a separate computing environment as thetraining phase 102. The various computing environment is described infurther detail below.

Attention now turns to a description of one aspect of the architectureof the neural network model.

A LSTM is a type of recurrent neural network capable of learning orderdependence in sequential patterns using a gradient-based learningalgorithm. In general, the LSTM architecture includes an input layer,one or more hidden layers in the middle with recurrent connectionsbetween the hidden layers at different times, and an output layer. Eachlayer represents a set of nodes and the layers are connected withweights. The input layer x_(t) represents an index at position t in avocabulary |V| and the output layer y_(t) produces a probabilitydistribution that the token at position t in the vocabulary is likely tocomplete a method invocation. The hidden layers h_(t) maintain arepresentation of the history of the training data. Gating units areused to modulate the input, output, and hidden-to-hidden transitions inorder to keep track of a longer history of the training data.

The LSTM is used to predict a token m*, conditional on an orderedsequence of syntax tokens, c_(t), t=0 . . . T, corresponding to theterminal nodes of the AST of code snippet C, plus the specialend-of-sequence token “.” The LSTM is defined as follows:x _(t) =Lc _(t),  (1)h _(t) =f(x _(t) ,h _(t)−1),  (2)P(m|C)=y _(t)=softmax(W h _(t) +b),  (3)m*=argmax(P(m|C)),  (4)

where:

x_(t) represents a word encoding of a token c_(t) in the word embeddingmatrix L, LϵR^(dx×|V|),

t represents a temporal dimension, such as a position of a token in theordered sequence of syntax tokens,

d_(x) is the word embedding dimension,

|V| is the size of the vocabulary,

h_(t) is the next hidden state and is based on the function f (x_(t),h_(t-1)), the function f (x_(t), h_(t-1)) represents the stacked LSTMtaking the current input, x_(t), and the previous hidden state, h_(t-1),to produce the next hidden state, h_(t),

WϵR^(|V|xd) _(h) is the output projection matrix,

bϵR^(|V|) is the bias,

d_(h) is the size of the hidden state of the LSTM,

softmax is a function that normalizes a vector of real numbers into aprobability distribution, and

argmax is an abbreviation for arguments of the maxima and in equation(3) represents the index in the vocabulary representing the token havingthe highest probability.

FIG. 2 illustrates an exemplary architecture of the deep learning model200. The neural network model 210 is trained on word embeddings 208representative of the syntactic structure of the context of a completedmethod invocation. The word embeddings 208 are generated from multipleordered sequences of tokens 206 generated from a depth-first ordertraversal of an abstract syntax tree 204. An ordered sequence of tokensrepresents the context of the completed method invocation from a sourcecode program 202.

The deep learning may use a two-stack LSTM 210 (LSTM1, LSTM2) with 100hidden units. However, it should be noted that the techniques disclosedherein are not limited to a two-stack LSTM implementation and that otherconfigurations are contemplated to achieve a desired performance (e.g.,2-stack or 3-stack LSTM with 64 hidden units).

The LSTMs are trained interactively, making multiple passes over thetraining dataset before converging to a minimum. Each training iterationincludes forward propagation, loss calculation, backpropagation stepsfollowed by updating the weights. A Stochastic Gradient Descent (SGD)method is the optimization algorithm used to find the values ofparameters of the function that minimizes the loss function. The lossfunction maybe a categorical cross-entropy algorithm. A backpropagationthrough time (BPTT) algorithm maybe used to update the weights.

Conventionally, in sequence classification tasks, the inputs and theoutputs are treated as isolated entities with no association betweenthem. In this deep learning architecture 200, there is a semanticrelationship between the inputs and outputs which can be utilized toreduce the size of the deep learning model. As such, the input wordembedding matrix 208 is reused in the output projection matrix 218 inorder to reduce the number of trainable variables in the model.

A linear projection layer 214 is a matrix A=(a)_(ij)ϵR^(dh×dx). Thelinear projection layer 214 is used to generate the predicted embeddingvectors 216 from the hidden state of LSTM at the last temporal step T asl_(j) ^(pred)=Σ_(i)h_(Ti)a_(ij). The hidden state vector h_(T)ϵR^(dh)encodes information learned by LSTM from the feature vector relevant tothe method completion. Finally, we obtain a probability distribution ofthe methods by first getting the unnormalized predictions asy_(k)=Σ_(j)l_(kj)l_(j) ^(pred)+b_(k), where b_(k), k=0 . . . |V|−1 isthe bias vector, and then normalizing them using softmax function.

Attention now turns to description of the various exemplary methods thatutilize the system and device disclosed herein. Operations for theaspects may be further described with reference to various exemplarymethods. It may be appreciated that the representative methods do notnecessarily have to be executed in the order presented, or in anyparticular order, unless otherwise indicated. Moreover, variousactivities described with respect to the methods can be executed inserial or parallel fashion, or any combination of serial and paralleloperations. In one or more aspects, the method illustrates operationsfor the systems and devices disclosed herein.

FIG. 3 illustrates an exemplary method 300 illustrating the training ofthe deep learning model. Referring to FIGS. 1 and 3, one or more sourcecode repositories 106 are searched for source code programs written in atarget programming language. The source code repositories 106 can bewidely-used code repositories, such as GitHub, internal coderepositories, and/or combinations thereof. The source code extractioncomponent 108 extracts a number and type of source code programs thatmeet an intended objective, such as source code programs that areaccessed frequently, source code programs that utilize a particularfunction (e.g., database operations, computer graphics programs,asynchronous methods, etc.), and the like. These source code programsare used to generate training and validation datasets (collectively,block 302).

Each selected source code program 110 is then parsed and/or compiled bythe compilation component 112 to produce an abstract syntax tree (block304).

For each method invocation in a selected source code program 110, afeature vector is generated representing the syntactic context of themethod invocation (block 306). The feature vector is an ordered sequenceof T tokens representative of the context of a complete methodinvocation. The ordered sequence of tokens is a serialized sequence ofsyntax nodes and tokens from the abstract syntax tree and the runtimedata type of the variable assigned to the result of the methodinvocation. The runtime data type of the variable is determined fromtraditional compiler techniques such as type inference, contextualtyping, duck typing, and the like.

The serialized sequence of syntax nodes and tokens is obtained fromtraversing the abstract syntax tree in depth first order (i.e., depthfirst search, depth first traversal). A depth first traversal starts ata root node and traverses the tree in a single path until it reaches aterminal or leaf node. The traversal then backtracks until it can chooseanother path to traverse. This process is repeated until all nodes arevisited (collectively, block 306).

Next, the feature vectors are transformed into numeric vectors and theninto word embeddings (block 308). The syntax nodes and token names aremapped to integers from 1 to V, where V is the size of the tokenvocabulary. The integers in a word embedding represent an index into thevocabulary that represents a particular token. Infrequently used tokensare removed in order to reduce the vocabulary size. Tokens that are notpart of the vocabulary (i.e., out-of-vocabulary tokens) are mapped tointegers greater than the vocabulary size, V, so that occurrences of thesame out-of-vocabulary token is represented by the same token. Variablenames chosen by a developer often differ between the different sourcecode programs. Keeping the variable names in the vocabulary increasesthe vocabulary size and makes the code completion system dependent onthe spelling of a variable name. In order to avoid this situation, thevariable names are normalized (collectively, block 308).

Next, the word embeddings 118 are input into the model trainingcomponent 120 to train the LSTM (block 310). Before the deep learningmodel is trained, a set of hyperparameters is selected randomly (block310). A hyperparameter is a parameter associated with the model trainingalgorithms and is set before the start of the model training Ahyperparameter is not learned by the deep learning or neural network.The hyperparameters are initialized with random values and then tunedbased on the performance of the LSTM when tested using the validationdataset. Table I below lists the hyperparameters that may be used totrain the LSTM for code completion.

TABLE 1 BEST HYPERPARAMETER DESCRIPTION VALUE Λ Learning rate 0.002 YLearning rate decay per epoch 0.97 N Number of recurrent neural 2network layers d_(h) Number of hidden units in 100 LSTM, per layer TNumber of lookback tokens, 100 timesteps through which thebackpropagation runs Type of recurrent Type of recurrent LSTM neuralnetwork neural network d_(b) Batch size 256 Loss function Type of lossfunction Categorical cross-entropy d_(x) Embedded vector dimension 150Optimizer Stochastic optimization scheme Adam Dropout Dropout keepprobability 0.8 L2 Regularization Weight regularization of all 10 layersClip norm Maximum norm of gradients 10 Token frequency Minimum frequencyof syntax 500 threshold token in the corpus for inclusion in thevocabulary

The training of the LSTM is a computationally intensive effort whichrequires parallel data processing. One or more clusters may be used totrain the LSTM where each cluster contains a set of loosely or tightlycoupled computers (e.g., processors, processing units, cores) thatperform the same task simultaneously under the control of distributedcontroller. Each computer works off the same copy of the LSTM and usesdistributed data parallel training algorithms to synchronize theprocessing between the clusters (collectively, block 310).

The LSTM is trained using batching where the training dataset ispartitioned into batches of a certain size and processed before the deeplearning model is updated. The size of a batch must be more than orequal to one and less than or equal to the number of samples in thetraining dataset (collectively, block 310).

FIG. 4 illustrates an exemplary batching technique used in training thedeep learning model. As shown in FIG. 4, each training sample 402A-402Nfrom each source code program 404A-404N is an ordered sequence of tokenshaving varying lengths with a maximum length of T. The training samplesare pre-sorted and split into three buckets based on their length 406A,406B, 406C. Within each bucket 406A, 406B, 406C, the token sequences arepadded to the maximum length using a special padding token which isexcluded from the cross-entropy loss calculation through masking. Atraining buffer maintains the token sequences belonging to d_(b)distinct token sequences. At every training step 408A, 408B, the firstT_(RNN) timesteps of the buffer are fed as the next batch. The buffer isshifted by T_(RNN). Every time a sequence is finished in the buffer, anew set of sequences in loaded and the LSTM internal states are resetfor training (collectively, block 310).

Deep learning models are typically trained via a stochastic optimizationprocedure. There are different types of stochastic gradient descentoptimizers and Adam, Adaptive Movement Estimation, is used by the modeltraining component 120. A learning rate tells the optimizer how far tomove the weights in the direction opposite of the gradient for amini-batch. If the learning rate is low, then training is more reliable,but optimization will take a lot of time because steps towards theminimum of the loss function are tiny. If the learning rate is high,then training may not converge or even diverge. Weight changes can be sobig that the optimizer overshoots the minimum and makes the loss worse(collectively, block 310).

An exponential learning rate schedule is used as follows:λ_(i)=λ₀*γ^(i), where λ₀ is the base learning rate, γ is the learningrate decay constant, and i is the epoch number. An epoch is a completepass through a training dataset. In the parallel distributed trainingprocess, the learning rate is scaled up during the first few epochs ofthe training to facilitate reliable model convergence. The learning rateis linearly scaled-up thereafter proportionally to the number ofprocessing units used in the distributed training process, N_(worker),during a warm-up period of four epochs as follows:

${{\lambda_{0}\left( N_{worker} \right)} = {\lambda_{0}\frac{N_{worker}}{\alpha}}},$where α is the scaling fraction controlling the maximum value of thelearning rate at the end of the warmup period, and N_(worker) is thenumber of processing units used in all the clusters (collectively, block310).

Before the LSTM is trained, a set of hyperparameters is selectedrandomly and then tuned to achieve a desired performance. The LSTM istested using a validation dataset to determine the appropriatehyperparameters settings to achieve a desired goal. When the desiredgoal is not achieved, one or more hyperparameters are adjusted and thetraining is repeated until the target goal is achieved (collectively,block 312).

Evaluation metrics are used to test the quality of the candidaterecommendations. In one aspect, a top-k accuracy method is used usingmean reciprocal rank (MRR) to perform the evaluation. Top-k accuracy isdefined as:

${{{Acc}(k)} = \frac{N_{{top} - k}}{Q}},$

and MMR is defined as:

${{MRR} = {\frac{1}{Q}{\sum\limits_{i = 1}^{Q}\frac{1}{{rank}_{i}}}}},$

where N_(top-k) denotes the number of relevant recommendations in thetop k suggestions, Q represents the total number of test data samples,and rank_(i) is the prediction rank of a recommendation.

Accuracy in the top-1 indicates how often the top recommendation iscorrect, while the top-5 accuracy indicates how often the top threerecommendations in the list contain the candidate the user is lookingfor. The MRR captures the rank of the result, thus providing informationoutside of the top candidate. A larger value of the MRR indicates theoverall smaller rank numbers of correct recommendations. (collectively,block 312).

Once the LSTM is tested to a desired target goal, model quantization isperformed (block 314). Neural network quantization is needed in order toreduce the number of bits used to store the weights. In order to reducememory, network bandwidth, and the size of the model, the weights areconverted from a 32-bit floating format into an 8-bit unsigned integernumeric format. Quantization is performed layer-by-layer extractingminimum and maximum values of weights and activations in the floatingpoint format, zero shifting, and scaling. Given a weight, W=w_(ij), fora layer, the quantized matrix W^(q) is obtained as follows:

${ß = \frac{{\max(W)} - {\min(W)}}{2^{8}}},{w_{ij}^{q} = {\frac{w_{{ij} - {\min{(W)}}}}{ß}.\mspace{14mu}\left( {{collectively},{{block}\mspace{14mu} 314}} \right).}}$

Upon completion of the model quantization, the LSTM is ready to bedeployed in a code completion system (block 316). Attention now turns toa discussion of the use of the deep learning model for code completion.

FIG. 5 illustrates an exemplary method 500 of code completion utilizingthe deep learning model. Referring to FIGS. 1 and 5, code completion isperformed in a development environment such as a source code editor 130.The source code editor 130 is configured to interact with a codecompletion component 142 that utilizes the deep learning model (block502). The source code editor 130 performs a background parsing processthat parses the source code in the source code editor to generate andupdate the abstract syntax tree of the source code (block 502).

The user interface 132 of the source code editor 130 detects the inputcharacters that a developer enters into the source code editor 130. Whenthe user interface 132 detects the marker character that denotes codecompletion is needed for a partial method invocation at a currentposition in the source code editor 130 (block 504), the user interface132 requests recommendations 138 from the code completion component 142(block 506). In one aspect, the detection of a period after a class nameis used as the trigger to invoke code completion (block 504).

The token sequence extraction component 116 utilizes the abstract syntaxtree generated during the source code editing session to obtain thefeatures needed to represent the syntactic context of the current methodinvocation (block 508). At this point, the token sequence contains themarker character and the tokens preceding the marker character (block508).

The token sequence extraction component 116 transforms the features intoword embeddings 144 which are input to the deep learning model 122(block 510). The deep learning model outputs a probability for eachtoken in the vocabulary (block 510). The tokens are ranked and thetokens with the k top highest probabilities are output by the deeplearning model 122 (block 512). The k top recommendations are thecandidates 136 that are returned to the user interface 132 for displayto the developer (block 514). A user may select at least one of thecandidates 136 which is then input into the source code program tocomplete the method invocation (block 516). The process is repeated(blocks 506-516) until the user closes the source code program.

Exemplary Operating Environment

Attention now turns to a discussion of an exemplary operatingenvironment. FIG. 6 illustrates an exemplary operating environment 600in which one or more computing devices 602 is used to train the deeplearning model and a second computing device 604 that uses the deeplearning model for code completion. However, it should be noted that theaspects disclosed herein is not constrained to any particularconfiguration of devices. Any one of the computing devices 602 mayutilize the deep learning model in its own code completion system andcomputing device 604 may generate and test the deep learning model aswell. Computing devices 602 may be configured as a cloud service thatgenerates the deep learning model as a service for other code completionsystems. It should be noted that the operating environment is notlimited to any particular configuration and other configurations arepossible.

The computing devices 602, 604 may be any type of electronic device,such as, without limitation, a mobile device, a personal digitalassistant, a mobile computing device, a smart phone, a cellulartelephone, a handheld computer, a server, a server array or server farm,a web server, a network server, a blade server, an Internet server, awork station, a mini-computer, a mainframe computer, a supercomputer, anetwork appliance, a web appliance, a distributed computing system,multiprocessor systems, or combination thereof. The operatingenvironment 600 may be configured in a network environment, adistributed environment, a multi-processor environment, or a stand-alonecomputing device having access to remote or local storage devices.

The computing devices 602, 604 may include one or more processors 608,640, a communication interface 610, 642, one or more storage devices612, 644, one or more input/output devices 614, 646, and a memory 616,648. A processor 608, 640 may be any commercially available orcustomized processor and may include dual microprocessors andmulti-processor architectures. The communication interface 610, 642facilitates wired or wireless communications between the computingdevice 602, 604 and other devices. A storage device 612, 644 may becomputer-readable medium that does not contain propagating signals, suchas modulated data signals transmitted through a carrier wave. Examplesof a storage device 612, 644 include without limitation RAM, ROM,EEPROM, flash memory or other memory technology, CD-ROM, digitalversatile disks (DVD), or other optical storage, magnetic cassettes,magnetic tape, magnetic disk storage, all of which do not containpropagating signals, such as modulated data signals transmitted througha carrier wave. There may be multiple storage devices 612, 644 in thecomputing devices 602, 604. The input/output devices 614, 646 mayinclude a keyboard, mouse, pen, voice input device, touch input device,display, speakers, printers, etc., and any combination thereof.

A memory 616, 648 may be any non-transitory computer-readable storagemedia that may store executable procedures, applications, and data. Thecomputer-readable storage media does not pertain to propagated signals,such as modulated data signals transmitted through a carrier wave. Itmay be any type of non-transitory memory device (e.g., random accessmemory, read-only memory, etc.), magnetic storage, volatile storage,non-volatile storage, optical storage, DVD, CD, floppy disk drive, etc.that does not pertain to propagated signals, such as modulated datasignals transmitted through a carrier wave. A memory 616, 648 may alsoinclude one or more external storage devices or remotely located storagedevices that do not pertain to propagated signals, such as modulateddata signals transmitted through a carrier wave.

Computing device 604 may utilize an integrated development environment(IDE) 654 that allows a user (e.g., developer, programmer, designer,coder, etc.) to design, code, compile, test, run, edit, debug or build aprogram, set of programs, web sites, web applications, and web servicesin a computer system. Software programs can include source code files,created in one or more source code languages (e.g., Visual Basic, VisualJ#, C++. C#, J#, Java Script, APL, COBOL, Pascal, Eiffel, Haskell, ML,Oberon, Perl, Python, Scheme, Smalltalk and the like). The IDE 654 mayprovide a native code development environment or may provide a managedcode development that runs on a virtual machine or may provide acombination thereof. The IDE 654 may provide a managed code developmentenvironment using the .NET framework. It should be noted that thisoperating embodiment is not constrained to providing the source codedevelopment services through an IDE and that other tools may be utilizedinstead, such as a stand-alone source code editor and the like.

A user can create and/or edit the source code program files 652according to known software programming techniques and the specificlogical and syntactical rules associated with a particular sourcelanguage via a user interface 658 and a source code editor 656 in theIDE 654. Thereafter, the source code program files 652 can be compiledvia a compilation component 660 generating data structures representingthe syntactic structure and semantic model of the source code.

The memory 648 of computing device 604 may contain instructions,components, and data. A component is a software program that performs aspecific function and is otherwise known as a module, program, and/orapplication. The memory 648 may include an operating system 650, one ormore source code program files 652, an IDE 654 that may include a sourcecode editor 656, a user interface 658, a compilation component 660, acode completion component 662 having a token sequence extractioncomponent 664 and the deep learning model 666 and other applications anddata 668.

The memory 616 of the computing devices 602 may include an operatingsystem 618, a source code extraction component 620, a token sequenceextraction component 622, a compilation component 624, a model trainingcomponent 626, a deep learning model 628, and other applications anddata 630.

The computing devices 602, 604 may be communicatively coupled via anetwork 606. The network 606 may be configured as an ad hoc network, anintranet, an extranet, a virtual private network (VPN), a local areanetwork (LAN), a wireless LAN (WLAN), a wide area network (WAN), awireless WAN (WWAN), a metropolitan network (MAN), the Internet, aportions of the Public Switched Telephone Network (PSTN), plain oldtelephone service (POTS) network, a wireless network, a WiFi® network,or any other type of network or combination of networks.

The network 606 may employ a variety of wired and/or wirelesscommunication protocols and/or technologies. Various generations ofdifferent communication protocols and/or technologies that may beemployed by a network may include, without limitation, Global System forMobile Communication (GSM), General Packet Radio Services (GPRS),Enhanced Data GSM Environment (EDGE), Code Division Multiple Access(CDMA), Wideband Code Division Multiple Access (W-CDMA), Code DivisionMultiple Access 2000, (CDMA-2000), High Speed Downlink Packet Access(HSDPA), Long Term Evolution (LTE), Universal Mobile TelecommunicationsSystem (UMTS), Evolution-Data Optimized (Ev-DO), WorldwideInteroperability for Microwave Access (WiMax), Time Division MultipleAccess (TDMA), Orthogonal Frequency Division Multiplexing (OFDM), UltraWide Band (UWB), Wireless Application Protocol (WAP), User DatagramProtocol (UDP), Transmission Control Protocol/Internet Protocol(TCP/IP), any portion of the Open Systems Interconnection (OSI) modelprotocols, Session Initiated Protocol/Real-Time Transport Protocol(SIP/RTP), Short Message Service (SMS), Multimedia Messaging Service(MMS), or any other communication protocols and/or technologies.

Conclusion

A system is disclosed having one or more processors and a memory. Thememory has one or more programs having instructions that are stored inthe memory and which are configured to be executed by the one or moreprocessors. The one or more programs include instructions that: detectin a source code editor, an input character signaling an initiation of amethod invocation; and predict at least one method to complete themethod invocation using a deep learning model, wherein the deep learningmodel is trained on ordered sequences of a context of the methodinvocation from source code programs. The instructions have furtherinstructions that: extract features representing the context of themethod invocation; and transform the features into numeric values. Theextracted features include a syntactic representation of the context ofthe method invocation from an abstract syntax tree of source codesurrounding the method invocation. The extracted features include aruntime type of a variable receiving a result of the method invocation.The ordered sequence of the context includes tokens obtained from adepth-first traversal of the abstract syntax tree. The deep learningmodel is a long short term memory network.

A method is disclosed comprising: obtaining training samples to train adeep learning model, the training samples representing a plurality ofordered sequences of tokens, an ordered sequence of tokens represents asyntactic context of a method invocation; inputting the training samplesinto the deep learning model; training the deep learning model with thetraining samples to output, a plurality of probabilities, a probabilityassociated with a select token from a vocabulary of tokens used in theplurality of ordered sequences of tokens; and incorporating the deeplearning model into a code completion tool for use in completing a codefragment initiating a method invocation.

The method further comprises generating at least one predicted embeddedvector representing a training sample, the at least one predictedembedded vector obtained as the product of a last temporal hidden stateof the deep learning model and a linear projection matrix. The trainingsamples are word embeddings derived from the plurality of orderedsequences of tokens.

The method further comprises calculating the plurality of probabilitiesas a product of the word embeddings and the at least one predictedembedded vector and generating at least one ordered sequence of tokensfrom an abstract syntax tree representation of a code snippet initiatingthe method invocation. The training of the deep learning model furthercomprises training the deep learning model using a plurality of paralleldistributed clusters. The training of the deep learning model furthercomprises using a stochastic gradient descent optimization process tominimize a categorical cross-entropy loss function and usingbackpropagation through time process to update weights of the deeplearning model.

A device is disclosed having at least one processor and at least onememory device. The at least one processor is configured to: obtain atraining dataset from source code programs having method invocations,the training dataset including a plurality of ordered sequences oftokens that represent a syntactic context of a method invocation; usethe training dataset to train a deep learning model to output, aplurality of probabilities, a probability associated with a select tokenfrom a vocabulary of tokens used in the plurality of ordered sequencesof tokens; and provide the deep learning model into a code completioncomponent to facilitate completion of a method invocation based on theplurality of probabilities generated from the deep learning model.

The deep learning model is a long short term memory network. Theplurality of ordered sequence of tokens is derived from an abstractsyntax tree representing a code snippet containing the methodinvocation. The training dataset is used to train a deep learning modelto output, a plurality of probabilities further comprises actions that:generate at least one predicted embedded vector representing a trainingsample of the training dataset, the at least one predicted embeddedvector obtained as the product of a last temporal hidden state of thedeep learning model and a linear projection matrix. The training sampleis a word embedding. The device is further configured to calculate theplurality of probabilities as a product of the word embeddings and thepredicted embedded vector.

Although the subject matter has been described in language specific tostructural features and/or methodological acts, it is to be understoodthat the subject matter defined in the appended claims is notnecessarily limited to the specific features or acts described above.Rather, the specific features and acts described above are disclosed asexample forms of implementing the claims.

What is claimed:
 1. A method, comprising: obtaining training samples totrain a deep learning model, the training samples representing aplurality of ordered sequences of tokens, an ordered sequence of tokensrepresents a syntactic context of a method invocation; inputting thetraining samples into the deep learning model; training the deeplearning model with the training samples to output, a plurality ofprobabilities, a probability associated with a select token from avocabulary of tokens used in the plurality of ordered sequences oftokens, wherein during the training of the deep learning model, at leastone predicted embedding vector is generated representing a trainingsample, the at least one predicted embedding vector obtained as theproduct of a last temporal hidden state of the deep learning model and alinear projection matrix; and incorporating the deep learning model intoa code completion tool for use in completing a code fragment initiatinga method invocation.
 2. The method of claim 1, wherein the syntacticcontext of the method invocation includes a datatype of a return valueof the method invocation.
 3. The method of claim 1, wherein the deeplearning model is based on one or more a long short-term memorynetworks.
 4. The method of claim 1, further comprising: calculating theplurality of probabilities as a product of the word embeddings and theat least one predicted embedding vector.
 5. The method of claim 1,further comprising: generating at least one ordered sequence of tokensfrom an abstract syntax tree representation of a code snippet initiatingthe method invocation.
 6. The method of claim 1, wherein training thedeep learning model further comprises: training the deep learning modelusing a plurality of parallel distributed clusters.
 7. The method ofclaim 1, wherein training the deep learning model further comprises:using a stochastic gradient descent optimization process to minimize acategorical cross-entropy loss function.
 8. The method of claim 1,wherein training the deep learning model further comprises: usingbackpropagation through time process to update weights of the deeplearning model.
 9. A device, comprising: at least one processor and atleast one memory device; wherein the at least one processor isconfigured to execute instructions on the at least one memory device toperform acts that: obtain a training dataset from source code programshaving method invocations, the training dataset including a plurality ofordered sequences of tokens that represent a syntactic context of amethod invocation; use the training dataset to train a deep learningmodel to output, a plurality of probabilities, a probability associatedwith a select token from a vocabulary of tokens used in the plurality ofordered sequences of tokens, wherein during the training of the deeplearning model, at least one predicted embedding vector is generatedrepresenting a training sample, the at least one predicted embeddingvector obtained as the product of a last temporal hidden state of thedeep learning model and a linear projection matrix; and provide the deeplearning model into a code completion component to facilitate completionof a method invocation based on the plurality of probabilities generatedfrom the deep learning model.
 10. The device of claim 9, wherein thedeep learning model is based on a long short term memory network. 11.The device of claim 9, wherein the plurality of ordered sequence oftokens is derived from an abstract syntax tree representing a codesnippet containing the method invocation.
 12. The device of claim 9,wherein the at least one processor is further configured to perform actsthat: perform model quantization prior to providing the deep learningmodel into a code completion component.
 13. The device of claim 9,wherein the syntactic context of the method invocation includes adatatype of a return value of the method invocation.
 14. The device ofclaim 9, wherein the at least one processor is further configured toperform acts that: calculate the plurality of probabilities as a productof the word embeddings and the predicted embedding vector.
 15. A system,comprising: one or more processors; and a memory; one or more programs,wherein the one or more programs are stored in the memory and configuredto be executed by the one or more processors, the one or more programsincluding instructions that: train a deep learning model to learn aprobability distribution for a vocabulary of tokens from a trainingdataset, the training dataset including a plurality of ordered sequencesof tokens obtained from source code programs having method invocations,wherein an ordered sequence of tokens represents a syntactic context ofa method invocation, wherein during the training of the deep learningmodel, at least one predicted embedding vector is generated representinga training sample from the training dataset, the at least one predictedembedding vector obtained as the product of a last temporal hidden stateof the deep learning model and a linear projection matrix; and deploythe deep learning model to predict candidates to complete a targetmethod invocation.
 16. The system of claim 15, wherein the probabilitydistribution is based on a product of word embeddings of the trainingdataset and the at least one predicted embedding vector.
 17. The systemof claim 15, wherein the syntactic context of a method invocationincludes a data type of a return value from the method invocation. 18.The system of claim 15, wherein the one or more programs includingfurther instructions that: perform model quantization prior todeployment of the deep learning model.
 19. The system of claim 15,wherein the deep learning model is based on a long short-term memorynetwork.
 20. The system of claim 15, wherein one or more of the tokensof the vocabulary of tokens represent method names.